import axios from "axios"
import baseurl from "./url.js"
import Vue from 'vue';
import {
  Toast
} from 'vant';
Vue.use(Toast);
axios.interceptors.request.use(function (config) {
    // Toast.loading({
    //   message: '加载中',
    //   forbidClick:true
    // });
    // config.headers["Authorization"] = "token"
    // config.withCredentials = true
    // return config

    Toast({
      // message: '自定义图片',
    });
    config.headers['Authorization'] = 'Bearer ' + "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwOi8vMTIwLjUzLjMxLjEwMzo4NC9hcGkvYWRtaW5Vc2VyL2xvZ2luIiwiaWF0IjoxNjMxNzc5MjU3LCJleHAiOjE2MzIwODE2NTcsIm5iZiI6MTYzMTc3OTI1NywianRpIjoiY0RHb0ZqSUYxWUJ5SldIVyIsInN1YiI6MSwicHJ2IjoiZTUzODQyOTgzNDYyYmQ4OTUyYWU1OTIzNjM3YWNhMGU5NmIyNTk4YyJ9.2zmwaGlVdWuEBlXuxPUqUdKlp3iUHnqeIJ4eiWxrAS0"
    config.withCredentials = false
    // xmlhttp.withCredentials = true  
    return config
  }),
  function (error) {
    return Promise.reject(error)
  }
export default function http(methods, url, data) {
  url = baseurl + url
  var p = new Promise((reslove, reject) => {
    if (methods == "get") {
      axios.get(url).then(res => {
        reslove(res)
      }).catch(error => {
        reject(error)
      })
    }
    if (methods == "post") {
      axios.post(url, data).then(res => {
        reslove(res)
      }).catch(error => {
        reject(error)
      })
    }
  })
  return p

}
